window.onload = function () {
    console.log("=========加载js=======")
    const container = document.getElementById('container');
    const signUpButton = document.getElementById('signUp');
    const signInButton = document.getElementById('signIn');
    const btnSignIn = container.querySelector('.btn-sign-in');
    const btnSignUp = container.querySelector('.btn-sign-up');

    signUpButton.onclick = function() {
        container.classList.add('penal-right-active');
    }

    signInButton.onclick = function() {
        container.classList.remove('penal-right-active');
    }

    btnSignIn.onclick = function () {
        const singin =  container.querySelector(".sign-in-container")
        const username = singin.querySelector("#username").value
        const password = singin.querySelector("#password").value
        const options = {
            url:"/action/login.do",
            method:"post",
            data:{
                username:username,
                password:password
            }
        }
        if (username && password) {
            httpRequest(options,callback)
        } else {
            alert("用户名密码不能为空！")
        }
    }
}


/**
 * 登陆成功，进入主页
 * @param res
 */
function callback(res) {
    if (typeof JSON.parse(res) === "object") {
        const {code,message,data:{user}} = JSON.parse(res)
        if (code === 200) {
            console.log("user:",user)
            location.href = "/home/home.html"
        } else {
            alert(message)
        }
    }
}
